package com.fzz.learning_forum.dao;

import com.fzz.learning_forum.domain.Article;
import com.fzz.learning_forum.domain.Comment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface CommentMapping {

    //发表评论
    @Insert("insert into tb_comment(reviewer,content,created,user_id,article_id) values(#{reviewer},#{content},#{created},#{user_id},#{article_id})")
    public Integer publishComment(Comment comment);

    //分页查询评论信息
    @Select("select * from tb_comment where article_id=#{article_id}")
    public List<Comment> selectCommentWithPage(@Param("article_id") Integer article_id);

    //查询自己评论过的动态
    @Select("select distinct tb_article.id,tb_article.content,tb_article.title,tb_article.tags,tb_article.created,tb_article.hit,tb_article.user_id,tb_article.article_img,tb_article.valid \n" +
            "from tb_article inner join tb_comment on tb_article.id=tb_comment.article_id\n"+
            "inner join tb_user on tb_comment.user_id=#{id}\n" +
            "inner join tb_reply on tb_comment.user_id=tb_reply.user_id")
    public List<Article> myCommentArticle(@Param("id")Integer id);

    //最新评论
    @Select("select distinct tb_comment.id,tb_comment.reviewer,tb_comment.content,tb_comment.created,tb_comment.user_id,tb_comment.article_id\n" +
            "from tb_article\n" +
            "inner join tb_user on tb_article.user_id=#{id}\n" +
            "inner join tb_comment on tb_article.id=tb_comment.article_id\n" +
            "order by id desc limit 5")
    public List<Comment> selectNewComment(@Param("id")Integer id);
}
